import { lineString } from "@turf/helpers";

/**
 * 生成抛物线坐标
 * @param {*} start 
 * @param {*} end 
 * @param {*} vertexLat 
 * @param {*} points 
 * @param {*} properties 
 * @returns 
 */
function generateParabola(
    start,
    end,
    vertexLat,
    points = 50,
    properties
) {
    const [lng1, lat1] = start;
    const [lng2, lat2] = end;
    const midLat = (lat1 + lat2) / 2;
    const midLng = (lng1 + lng2) / 2;

    const coords = [];
    for (let i = 0; i <= points; i++) {
        const t = i / points;
        const lat =
            (1 - t) ** 2 * lat1 + 2 * (1 - t) * t * vertexLat + t ** 2 * lat2;
        const lng =
            (1 - t) ** 2 * lng1 + 2 * (1 - t) * t * midLng + t ** 2 * lng2;
        coords.push([lng, lat]);
    }
    // return coords;
    return lineString(coords, properties);
}

export default generateParabola;
export { generateParabola };
